package com.sikaryofficial.workbench.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.common.core.web.page.PageDomain;
import com.sikaryofficial.workbench.domain.dto.req.order.OrderHeaderUpdateReq;
import com.sikaryofficial.workbench.domain.dto.req.order.OrderItemPriceReq;
import com.sikaryofficial.workbench.domain.dto.resp.SysDictDataDTO;
import com.sikaryofficial.workbench.domain.dto.resp.order.OrderDTO;
import com.sikaryofficial.workbench.domain.dto.resp.order.OrderItemDTO;
import com.sikaryofficial.workbench.manager.OrderManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 运营侧-订单Controller
 *
 * @author wuweihong
 * @date 2024-09-23
 */
@RestController
@RequestMapping("/order/backend")
@Api(tags = "运营侧-订单模块")
public class OrderBackendController     {

	@Autowired
	private OrderManager orderManager;

	@ApiOperation("运营侧-查询订单列表")
	@PostMapping("/operation/listPage")
	public PageResult<OrderDTO> opListPage(@RequestBody PageDomain page) {
		IPage<OrderDTO> iPage = orderManager.operateOrderList(page);
		return PageUtil.success(iPage.getRecords(), iPage.getTotal());
	}

	@ApiOperation("运营侧-更新订单状态")
	@PostMapping("/refreshOrderStatus")
	public R<Void> refreshOrderItemStatus(@RequestBody OrderHeaderUpdateReq req) {
		orderManager.refreshOrderStatus(req.getOrderHeaderId(), req.getStatus());
		return R.ok();
	}

	@ApiOperation("运营侧-订单状态枚举")
	@GetMapping("/getOrderStatusEnum")
	public R<List<SysDictDataDTO>> getOrderStatusEnum() {
		return R.ok(orderManager.getOrderHeaderStatusEnum());
	}

	@ApiOperation("运营侧-更新主订单")
	@PostMapping("/updateOrderHeader")
	public R<OrderDTO> updateOrderHeader(@Validated @RequestBody OrderHeaderUpdateReq req) {
		return R.ok(orderManager.updateOrderHeader(req));
	}

	@ApiOperation("运营侧-更新子订单")
	@PostMapping("/updateOrderItem")
	public R<OrderItemDTO> updateOrderItem(@Validated @RequestBody OrderItemPriceReq req) {
		return R.ok(orderManager.updateOrderItem(req));
	}

}
